{aide_template 'common/header'}
<link href="{$aideUrl}web/resource/css/util.min.css" rel="stylesheet">
<script type="text/javascript" src="{$aideUrl}web/resource/js/util.min.js?v=20170912"></script>
<style>
    .nameSpan{display: inline-block;width: 18%}
    .leftW{margin-left: 10%}
    #gbin1-list{margin-bottom: 10px}

    .basic-rules{display:none}
    .field-rules{display:none}
    .zimu{min-width:70px;}
    .xialafield{min-width:150px;}
    .rule-list .form-control{margin-right:5px;}
    .alertContent-con>span{color:#657cea}
</style>
<script src="{$aideUrl}web/resource/js/notice.js"></script>
<ul class="nav nav-tabs">
    <li class="active">活动-{$activity['title']}</li>
</ul>

<div class="main">
    <form action="" method="post" class="form-horizontal form"
          enctype="multipart/form-data" id="dataForm">
        <div class="panel panel-info">
            <div class="panel-heading">
                编辑号码规则
            </div>
            <div class="panel-body">
                <div class="form-group">
                    <div class="col-sm-8 col-xs-12">说明：号码规则由 首字母 + {$figure}位数字组成，比如：A{php echo str_repeat('8',$figure);}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label">状态</label>
                    <div class="col-sm-7 col-xs-12">
                        <label  class="radio-inline"><input type="radio" name="status" value="0" {if $nr['status']==0}checked="checked"{/if}/> 关闭</label>
                        &nbsp;&nbsp;&nbsp;
                        <label  class="radio-inline"><input type="radio" name="status" value="1" {if $nr['status']==1}checked="checked"{/if}/> 基本规则(所有项目统一)</label>
                        &nbsp;&nbsp;&nbsp;
                        <label  class="radio-inline"><input type="radio" name="status" value="2" {if $nr['status']==2}checked="checked"{/if}/> 分配规则(项目单独设置)</label>
                    </div>
                </div>
                <div class="rules-main">
                    <div class="basic-rules">
                        <div class="form-group">
                            <label class="control-label col-sm-2">规则</label>
                            <div class="col-sm-9 form-inline">
                                <span class="form-control">首字母<font color="#999999">(不能重复)</font></span>
                                <span class="form-control">数字最小值<font color="#999999">(1~{php echo str_repeat('9',$figure);})</font></span>
                                <span class="form-control info">数字最大值<font color="#999999">(1~{php echo str_repeat('9',$figure);})</font></span>
                                <span class="btn btn-info" onclick="addRuleRow()">添加规则</span>
                            </div>
                        </div>
                        <div class="rule-list" id="rule-list">
                            {loop $number_rule1 $key=>$val}
                            <div class="form-group">
                                <label class="control-label col-sm-2"></label>
                                <div class="col-sm-9 form-inline">
                                    <select class="form-control zimu" name="zimu[]">
                                        {loop $letters $k=>$v}
                                        <option {if $key==$v}selected="selected"{/if}>{$v}</option>
                                        {/loop}
                                    </select>
                                    <input type="number" class="form-control" size="1" oninput="if(value.length>{$figure})value=value.slice(0,{$figure})" name="min_num[]" value="{$val[0]}"/>
                                    <input type="number" class="form-control" size="2" oninput="if(value.length>{$figure})value=value.slice(0,{$figure})" name="max_num[]" value="{$val[1]}"/>
                                    <span class="btn btn-danger" size="2" onclick="$(this).parent().parent().remove()">删除</span>
                                </div>
                            </div>
                            {/loop}
                        </div>
                    </div>
                    <div class="field-rules">
                        <div class="field-box">
                            {loop $number_rule2 $key=>$val}
                            <div class="form-group">
                                <label class="control-label col-sm-2">{$options[$key]['name']}</label>
                                <div class="col-sm-9 form-inline">
                                    <span class="form-control">首字母<font color="#999999">(不能重复)</font></span>
                                    <span class="form-control">数字最小值<font color="#999999">(1~{php echo str_repeat('9',$figure);})</font></span>
                                    <span class="form-control info">数字最大值<font color="#999999">(1~{php echo str_repeat('9',$figure);})</font></span>
                                    <span class="btn btn-info" onclick="addRuleRow{$key}()">添加规则</span>
                                </div>
                            </div>
                            <div class="rule-list rule-list-{$key}">
                                {loop $val $k=>$v}
                                <div class="form-group">
                                    <label class="control-label col-sm-2"></label>
                                    <div class="col-sm-9 form-inline">
                                        <select class="form-control zimu" name="zimu_{$key}[]">
                                            {loop $letters $kk=>$vv}
                                            <option {if $k==$vv}selected="selected"{/if}>{$vv}</option>
                                            {/loop}
                                        </select>
                                        <input type="number" class="form-control" size="1" oninput="if(value.length>{$figure})value=value.slice(0,{$figure})" name="min_num_{$key}[]" value="{$v[0]}"/>
                                        <input type="number" class="form-control" size="2" oninput="if(value.length>{$figure})value=value.slice(0,{$figure})" name="max_num_{$key}[]" value="{$v[1]}"/>
                                        <span class="btn btn-danger" size="2" onclick="$(this).parent().parent().remove()">删除</span>
                                    </div>
                                </div>
                                {/loop}
                            </div>
                            {/loop}
                            <script>
                                {loop $number_rule2 $key=>$val}
                                function addRuleRow{$key}(){
                                    var rowText = '<div class="form-group">';
                                    rowText += '<label class="control-label col-sm-2"></label>';
                                    rowText += '<div class="col-sm-9 form-inline">';
                                    rowText += '<select class="form-control zimu" name="zimu_{$key}[]">';
                                    {loop $letters $k=>$v}
                                    rowText += "<option>{$v}</option>";
                                    {/loop}
                                        rowText += '</select>';
                                        rowText += '<input type="number" class="form-control" size="1" oninput="if(value.length>{$figure})value=value.slice(0,{$figure})" name="min_num_{$key}[]"/>';
                                        rowText += '<input type="number" class="form-control" size="1" oninput="if(value.length>{$figure})value=value.slice(0,{$figure})" name="max_num_{$key}[]"/>';
                                        rowText += '<span class="btn btn-danger" size="2" onclick="$(this).parent().parent().remove()">删除</span>';
                                        rowText += '</div>';
                                        rowText += '</div>';
                                        $(".rule-list-{$key}").append(rowText);
                                    }
                                    {/loop}
                            </script>
                        </div>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-xs-12 col-sm-3 col-md-2 control-label"></label>
                    <div class="col-sm-9 col-xs-12">
                        <input name="submit" type="button" value="提交" class="btn btn-primary span3" onclick="submitForm()">
                        <input type="hidden" name="token" value="{$_W['token']}" />
                    </div>
                </div>
            </div>
        </div>
        <input type="hidden" name="aid" value="{$aid}" />
        <input type="hidden" name="id" value="{$nr['id']}" />
    </form>

    <script>
        function submitForm(){
            $.ajax({
                url:"{php echo web_url('activity/numberrule/modify');}",
                data:$("#dataForm").serialize(),
                dataType:"json",
                type:"post",
                success:function(res){
               console.log(res)
                    if(res.code == 0){
                        util.tips(res.msg, 2000);
                    }else if(res.code == 1){
                        util.tips(res.msg);
                        setTimeout(function (){location.href ="javascript:history.go(-1)"},1000);
                    }
                }
            })
        }
        function addRuleRow(){
            var rowText = '<div class="form-group">';
            rowText += '<label class="control-label col-sm-2"></label>';
            rowText += '<div class="col-sm-9 form-inline">';
            rowText += '<select class="form-control zimu" name="zimu[]">';
            {loop $letters $v}
            rowText += "<option>{$v}</option>";
            {/loop}
                rowText += '</select>';
                rowText += '<input type="number" class="form-control" size="1" oninput="if(value.length>{$figure})value=value.slice(0,{$figure})" name="min_num[]"/>';
                rowText += '<input type="number" class="form-control" size="2" oninput="if(value.length>{$figure})value=value.slice(0,{$figure})" name="max_num[]"/>';
                rowText += '<span class="btn btn-danger" size="2" onclick="$(this).parent().parent().remove()">删除</span>';
                rowText += '</div>';
                rowText += '</div>';
                $("#rule-list").append(rowText);
            }
            $(function(){
                $("input[name='status']").change(function(){
                    $(".rules-main").children().hide();
                    var status = $(this).val();
//            console.log(status);
                    if(status == 1){
                        $(".basic-rules").show();
                    }else if(status == 2){
//                $(".xialafield").trigger("change");
                        $(".field-rules").show();
                    }
                });
                $("input[name='status'][checked='checked']").trigger("change");
            })
            {if $arrayLevel!=3}
            $("input[name='status']").change(function(){
                var fieldid ={$aid};
                if(fieldid > 1){
                    $.ajax({
                        url:"{php echo web_url('activity/numberrule/ajaxnumberrule');}",
                        data : {fieldid:fieldid},
                        type : 'post',
                        success : function(res){
                            $(".field-box").html(res);
                        }
                    })
                }
            })
            {/if}
    </script>
    <script type="text/javascript" src="../addons/jy_signup_a/js/jquery.sortable.js"></script>
</div>

{aide_template 'common/footer'}
